package com.aptech.test;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetCookies extends HttpServlet {
//ServletConfig sc;
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println(getServletConfig().getServletContext().getAttribute("test"));
        Cookie[] cs = request.getCookies();
        if (cs != null) {
            for (int i = 0; i < cs.length; i++) {
                Cookie c1 = cs[i];
                if (c1.getName().equals("username")) {
                    request.getSession().setAttribute("username", c1.getValue());
                }
                if (c1.getName().equals("password")) {
                    request.getSession().setAttribute("password", c1.getValue());
                }
            }
        }
        request.getRequestDispatcher("/testCookie.jsp").forward(request, response);
    }

//    public void init(ServletConfig config) throws ServletException {
//        sc = config;
//    }
}
